Ext.define('AM.controller.Users', {
    extend: 'Ext.app.Controller',
	views:['UserList'],
	stores:["Users"],
	models:["User"],
	init:function(){
		this.control({
			'userlist button[id=new]':{
				click:function(o){
					
				}
			},
			'userlist button[id=update]':{
				click:function(o){
					Ext.Msg.alert("","update");
				}
			},
			'userlist button[id=delete]':{
				click:function(o){
					var grid = o.ownerCt.ownerCt;
					var selectItems = grid.getSelectionModel().getSelection();
					if(selectItems.length == 0){
						Ext.Msg.alert("提示","您最少要选择一条数据");
					}else{
						//得到数组的主键，本处为name
						var store = grid.getStore();
						var ids = [];
						Ext.Array.each(selectItems,function(record){
							ids.push(record.get('name'));
						});
						//向服务器发起ajax请求
						Ext.Ajax.request({
							url:'/laoluo-erp/lesson!deleteUsers.action',
							params:{ids:ids.join(",")},
							timeout:3000,
							method:"POST",
							success:function(response){
								alert(response.responseText);
								Ext.Array.each(selectItems,function(item){
									store.remove(item);//刷新store
								});
							}
						});
						
					}
				}
			},
			'userlist button[id=cancel]':{
				click:function(o){
					Ext.Msg.alert("","cancel");
				}
			}
		});
	}
});